/*
   Receiving a DataFrame.
 */
#ifndef DATAFRAME_H
#define DATAFRAME_H

#include "Arduino.h"


#define DF_HEAD 0xFF


typedef enum {
    RECV_START, RECEIVING, RECV_DONE, ERR_UNKNOWN, ERR_OVERFLOW
} status_t;


typedef struct {
    uint8_t *buf;               // buffer received bytes
    uint16_t buf_size;          // size of buffer, in bytes
    uint16_t received;          // the number of received bytes (also points to the index of next available char)
    uint16_t frame_size;        // size of Frame, in bytes, excluding frame head
    bool escape;                 // if the last in char is DF_HEAD ?
} DataFrame;


void DF_Init(DataFrame *df, uint8_t buffer[], uint16_t buf_size, uint16_t frame_size);
status_t DF_Feed(DataFrame *df, int ch);


#endif  // DATAFRAME_H

